<style>
	page {
		background-color: white;
	}
</style>
<style lang="scss" scoped>
	.content {

		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}


	.footer {
		width: 100%;
		background-color: white;
		position: fixed;
		bottom: 0;
		left: 0;
		border-top: 1px solid #cccccc;
		padding-left: 30rpx;
		padding-right: 30rpx;
		z-index: 100;
	}


	.sbtn {
		width: 176rpx;
		height: 88rpx;
		border: 2rpx solid #dee2ee;
		border-radius: 46rpx;
	}

	.lbtn {
		width: 484rpx;
		margin-right: 0;
	}

	.line {
		width: 100%;
		height: 100rpx;
		border-bottom: 1px solid #eeeeee;
		padding: 0 20rpx;

		.ipt {
			width: 500rpx;
			text-align: right;
		}
	}

	.choosebox {
		padding: 30rpx;
		flex-wrap: wrap;

		.item {
			width: 216rpx;
			height: 116rpx;
			border: 2rpx solid #dee2ee;
			border-radius: 8rpx;
			margin-bottom: 30rpx;
			margin-right: 20rpx;
			color: #999;

		}

		.item:nth-child(3n) {
			margin-right: 0;
		}

		.greenbg {
			background: #dff7df;
			color: #2d405e;
			border: none;
		}

		.redbg {
			background: #ffe6e6;
			color: #2d405e;
			border: none;
		}

		.bluebg {
			background: #f5faff;
			color: #2d405e;
			border: none;
			border: 4rpx solid #409eff;
		}
	}
</style>

<template>
	<view class="content">
		<view class="line between-flex f28">
			<view class="gray"><span class="red">*</span>会议日期</view>
			<view class="blue">{{date}}
			</view>
		</view>
		<view class="choosebox flex">
			<view class="item colum-flex" @click="choose(item,index)" :class="item.checked?'bluebg':item.isOvertime==2?'redbg':item.isOvertime==1?'':item.isOvertime==0?'greenbg':''" v-for="item,index in meetingTime"
				:key="index">
				<view>{{item.startTime}}-{{item.endTime}}</view>
				<view>{{item.isOvertime==2?'已预订':item.isOvertime==1?'已过期':'可预订'}}</view>
			</view>
		</view>
		<view class="space"></view>
		<view class="footer between-flex paddingBottom">
			<view class="sbtn center-flex textColor bold f32" @click="$back()">返回</view>
			<view class="lbtn" @click="confirm">确定</view>
		</view>


	</view>
</template>

<script>
	export default {

		data() {
			return {

				head: this.$head,
				date: '',
				id:0,
				meetingTime:[],
				chooseArr:[]
			}
		},
		onLoad(e) {
			this.date = e.date
			this.id=e.id
			this.getMeetingTime()
		},
		methods: {
			confirm(){
				var arr=[]
				this.meetingTime.forEach(item=>{
					if(item.checked){
						arr.push(item)
					}
				})
				uni.$emit('chooseMeetingTime',arr)
				this.$back()
			},
			choose(item,index){
				console.log(index)
				if(item.isOvertime!=0){
					return
				}
				var startcurrent=-1
				var endcurrent=-1
			
			
				for(let i=0;i<this.meetingTime.length;i++){
					
					if(this.meetingTime[i].checked==true){
						if(startcurrent==-1){
							startcurrent=i
						}
						
						endcurrent=i
					}
				}
				
				if(startcurrent==-1){
					this.meetingTime[index].checked?this.meetingTime[index].checked=false:this.meetingTime[index].checked=true;
				}else{
					if(index-startcurrent<-1||index-endcurrent>1){
						this.$msg('请选择连续的时间段！')
					}else{
						this.meetingTime[index].checked?this.meetingTime[index].checked=false:this.meetingTime[index].checked=true;
					}
				}
					
					
				this.$forceUpdate()
			},
			getMeetingTime() {
				this.$pop.ajaxPost('/bus/busMeetingRoomTime/getByMeetingRoomId',{
					meetingRoomId:this.id,
					time:this.date
				}).then(res=>{
					this.meetingTime=res.body
				})
			}

		}
	}
</script>
